package tazadum.engine.trigger;

public class LeakyIntegrator {
	private final float dampening;
	public float value;

	public LeakyIntegrator(final float dampening) {
		this.dampening = dampening;
	}

	public float apply(final float dt, final float value) {
		if (value >= this.value) {
			this.value += value * dt;
			if (this.value > 1) {
				this.value = 1;
			}
		} else {
			this.value -= dampening * dt;
			if (this.value < 0) {
				this.value = 0;
			}
		}
		return this.value;
	}
}
